define([
    "jquery",
    "IO",
    "bootbox"
], function ($, IO, bootbox) {
    $(function () {

        var year_1 = 1;
        var year_2 = 2;
        var year_3 = 3;

        var activity_mid=$("#activity_mid_hidden").val();

        $("#btnSave1").click(function(){
            var a1=$('.a1').text()==""?"0":$('.a1').text();
            var a2=$('.a2').text()==""?"0":$('.a2').text();
            var a3=$('.a3').text()==""?"0":$('.a3').text();
            var a4=$('.a4').text()==""?"0":$('.a4').text();
            var a6=$('.a6').text()==""?"0":$('.a6').text();
            var a7=$('.a7').text()==""?"0":$('.a7').text();

            var a11=$('.a11').text()==""?"0":$('.a11').text();
            var a22=$('.a22').text()==""?"0":$('.a22').text();
            var a33=$('.a33').text()==""?"0":$('.a33').text();
            var a44=$('.a44').text()==""?"0":$('.a44').text();
            var a66=$('.a66').text()==""?"0":$('.a66').text();
            var a77=$('.a77').text()==""?"0":$('.a77').text();

            var group_mid= $("#selectGroup1 option:selected").attr("data-id");
            var year_id=1;
            if(group_mid=="undefined"){
                alert("请选择公司");
                return;
            }
            var parmas={};

            for(var i=0;i<2;i++){
                if(i==0){
                    parmas.advertising_expenditure=a1;
                    parmas.agency_price=a2;
                    parmas.terminal_price=a3;
                    parmas.market_value=a4;
                    parmas.production_name=a6;
                    parmas.market=a7;
                }
                else{
                    parmas.advertising_expenditure=a11;
                    parmas.agency_price=a22;
                    parmas.terminal_price=a33;
                    parmas.market_value=a44;
                    parmas.production_name=a66;
                    parmas.market=a77;
                }
                parmas.group_mid=group_mid;
                parmas.year_id=year_id;
                parmas.activity_mid=activity_mid;
                if(isNaN(parmas.advertising_expenditure)||isNaN(parmas.agency_price)||isNaN(parmas.terminal_price)||isNaN(parmas.market_value)){
                    alert("请输入数字");
                    return;
                }
                var j=1;
                IO.post('/shapan/api/adverShow',parmas,function(d){
                    if(j==2){
                        alert("提交成功");
                    }
                    j++;
                });
            }

        });
        $("#btnSave2").click(function(){
            var group_mid= $("#selectGroup2 option:selected").attr("data-id");
            var b1=$('.b1').text()==""?"0":$('.b1').text();
            var b2=$('.b2').text()==""?"0":$('.b2').text();
            var b3=$('.b3').text()==""?"0":$('.b3').text();
            var b4=$('.b4').text()==""?"0":$('.b4').text();
            var b6=$('.b6').text()==""?"0":$('.b6').text();
            var b7=$('.b7').text()==""?"0":$('.b7').text();

            var b11=$('.b11').text()==""?"0":$('.b11').text();
            var b22=$('.b22').text()==""?"0":$('.b22').text();
            var b33=$('.b33').text()==""?"0":$('.b33').text();
            var b44=$('.b44').text()==""?"0":$('.b44').text();
            var b66=$('.b66').text()==""?"0":$('.b66').text();
            var b77=$('.b77').text()==""?"0":$('.b77').text();

            var b111=$('.b111').text()==""?"0":$('.b111').text();
            var b222=$('.b222').text()==""?"0":$('.b222').text();
            var b333=$('.b333').text()==""?"0":$('.b333').text();
            var b444=$('.b444').text()==""?"0":$('.b444').text();
            var b666=$('.b666').text()==""?"0":$('.b666').text();
            var b777=$('.b777').text()==""?"0":$('.b777').text();
            var year_id=2;

            var parmas2={};
            var k=1;
            for(var j=0;j<3;j++){
                if(j==0){
                    parmas2.advertising_expenditure=b1;
                    parmas2.agency_price=b2;
                    parmas2.terminal_price=b3;
                    parmas2.market_value=b4;
                    parmas2.production_name=b6;
                    parmas2.market=b7;
                }

                else if(j==1){
                    parmas2.advertising_expenditure=b11;
                    parmas2.agency_price=b22;
                    parmas2.terminal_price=b33;
                    parmas2.market_value=b44;
                    parmas2.production_name=b66;
                    parmas2.market=b77;
                }
                else{
                    parmas2.advertising_expenditure=b111;
                    parmas2.agency_price=b222;
                    parmas2.terminal_price=b333;
                    parmas2.market_value=b444;
                    parmas2.production_name=b666;
                    parmas2.market=b777;
                }
                parmas2.group_mid=group_mid;
                parmas2.year_id=year_id;
                parmas2.activity_mid=activity_mid;
                if(isNaN(parmas2.advertising_expenditure)||isNaN(parmas2.agency_price)||isNaN(parmas2.terminal_price)||isNaN(parmas2.market_value)){
                    alert("请输入数字");
                    return;
                }
                IO.post('/shapan/api/adverShow',parmas2,function(d){
                    if(k==3){
                        alert(d.msg);
                    }
                    k++;
                });

            }
        });
        $("#btnSave3").click(function(){

            var group_mid3= $("#selectGroup3 option:selected").attr("data-id");

            var c1=$('.c1').text()==""?"0":$('.c1').text();
            var c2=$('.c2').text()==""?"0":$('.c2').text();
            var c3=$('.c3').text()==""?"0":$('.c3').text();
            var c4=$('.c4').text()==""?"0":$('.c4').text();
            var c6=$('.c6').text()==""?"0":$('.c6').text();
            var c7=$('.c7').text()==""?"0":$('.c7').text();

            var c11=$('.c11').text()==""?"0":$('.c11').text();
            var c22=$('.c22').text()==""?"0":$('.c22').text();
            var c33=$('.c33').text()==""?"0":$('.c33').text();
            var c44=$('.c44').text()==""?"0":$('.c44').text();
            var c66=$('.c66').text()==""?"0":$('.c66').text();
            var c77=$('.c77').text()==""?"0":$('.c77').text();

            var c111=$('.c111').text()==""?"0":$('.c111').text();
            var c222=$('.c222').text()==""?"0":$('.c222').text();
            var c333=$('.c333').text()==""?"0":$('.c333').text();
            var c444=$('.c444').text()==""?"0":$('.c444').text();
            var c666=$('.c666').text()==""?"0":$('.c666').text();
            var c777=$('.c777').text()==""?"0":$('.c777').text();
            var year_id=3;

            var parmas3={};
            var k=1;
            for(var i=0;i<3;i++){
                if(i==0){
                    parmas3.advertising_expenditure=c1;
                    parmas3.agency_price=c2;
                    parmas3.terminal_price=c3;
                    parmas3.market_value=c4;
                    parmas3.production_name=c6;
                    parmas3.market=c7;
                }
                else if(i==1){
                    parmas3.advertising_expenditure=c11;
                    parmas3.agency_price=c22;
                    parmas3.terminal_price=c33;
                    parmas3.market_value=c44;
                    parmas3.production_name=c66;
                    parmas3.market=c77;
                }
                else{
                    parmas3.advertising_expenditure=c111;
                    parmas3.agency_price=c222;
                    parmas3.terminal_price=c333;
                    parmas3.market_value=c444;
                    parmas3.production_name=c666;
                    parmas3.market=c777;
                }
                parmas3.group_mid=group_mid3;
                parmas3.year_id=year_id;
                parmas3.activity_mid=activity_mid;
                if(isNaN(parmas3.advertising_expenditure)||isNaN(parmas3.agency_price)||isNaN(parmas3.terminal_price)||isNaN(parmas3.market_value)){
                    alert("请输入数字");
                    return;
                }
                IO.post('/shapan/api/adverShow',parmas3,function(d){
                    if(k==3){
                        alert(d.msg);
                    }
                    k++;
                });
            }
        });

    })

})